package com.example.bughuangkai.service.impl;

import com.example.bughuangkai.entity.BugHistory;
import com.example.bughuangkai.mapper.BugHistoryMapper;
import com.example.bughuangkai.service.BugHistoryService;
import com.example.bughuangkai.vo.ReturnT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description bughistory
 * @author 黄凯
 * @date 2022-02-12
 */
@Service
public class BugHistoryServiceImpl implements BugHistoryService {

	@Autowired
	private BugHistoryMapper bughistoryMapper;

	@Override
	public ReturnT insert(BugHistory bughistory) {

		// valid
		if (bughistory == null) {
			return ReturnT.error("必要参数缺失");
        }

		bughistoryMapper.insert(bughistory);
        return ReturnT.success();
	}


	@Override
	public ReturnT delete(int id) {
		int ret = bughistoryMapper.delete(id);
		return ret>0?ReturnT.success():ReturnT.error();
	}


	@Override
	public ReturnT update(BugHistory bughistory) {
		int ret = bughistoryMapper.update(bughistory);
		return ret>0?ReturnT.success():ReturnT.error();
	}


	@Override
	public BugHistory load(int id) {
		return bughistoryMapper.load(id);
	}


	@Override
	public Map<String,Object> pageList(int offset, int pagesize) {

		List<BugHistory> pageList = bughistoryMapper.pageList(offset, pagesize);
		int totalCount = bughistoryMapper.pageListCount(offset, pagesize);

		// result
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("pageList", pageList);
		result.put("totalCount", totalCount);

		return result;
	}

}